package com.example.demo.common;

import com.example.demo.entity.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class UserSessionTools {

    /*获取当前用户登录*/
    public static UserInfo getLoginUser(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        Object userObj = null;
        if (session != null &&  //在赋值的同时进行判断（就直接判断userObj是否为空）
                (userObj = session.getAttribute(ApplicationVariable.SESSION_KEY_USERINFO)) != null)
            return (UserInfo) userObj;
        return null;
    }
}
